//-----------------------------------------------------------------------
// <copyright file="Node.h" company="Microsoft">
//      Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// Module:
//      Node.h
//
// Description:
//      Node Class
//
//-----------------------------------------------------------------------
#pragma once

#include "Common.h"

typedef map<CONTENT_ID, CContent*> CONTENTMAP;

class CNodeBase
{
public:
    enum NodeType
    {
        NodeTypeUndefined,
        NodeTypeApplication,
        NodeTypeNotification,
        NodeTypeDefaultBackground
    };

    CNodeBase()
    {}

    virtual ~CNodeBase()
    {}

    HRESULT SetTitle(LPCWSTR wszTitle)
    {
        HRESULT hr = S_OK;
        try
        {
            m_strTitle = wszTitle;
        }
        catch (...)
        {
            hr = E_FAIL;
        }
        return hr;
    }
    
    HRESULT SetBody(LPCWSTR wszBody)
    {
        HRESULT hr = S_OK;
        try
        {
            m_strBody = wszBody;
        }
        catch(...)
        {
            hr = E_FAIL;
        }
        return hr;
    }
    
    HRESULT SetIcon(const BYTE *pIcon, size_t cbIcon)
    {
        return m_Icon.SetData(pIcon, cbIcon);
    }
    
    HRESULT SetMiniIcon(const BYTE *pMiniIcon, size_t cbMiniIcon)
    {
        return m_MiniIcon.SetData(pMiniIcon, cbMiniIcon);
    }
    
    LPCWSTR GetTitle() { return m_strTitle.c_str(); }
    LPCWSTR GetBody() { return m_strBody.c_str(); }
    CSSIcon* GetIcon() { return &m_Icon; }
    CSSIcon* GetMiniIcon() { return &m_MiniIcon; }
    
public:
    NodeType m_nodeType;
    GUID m_guidApplicationId;
    
private:
    wstring m_strTitle;
    wstring m_strBody;
    CSSIcon m_Icon;
    CSSIcon m_MiniIcon;
};


class CNodeApplication : public CNodeBase
{
public:
    CNodeApplication(const GUID& guidApplicationId)
    {
        m_nodeType = NodeTypeApplication;
        m_guidApplicationId = guidApplicationId;
    }

    virtual ~CNodeApplication()
    {
        RemoveAllContent();
    }

    HRESULT AddContent(CONTENT_ID contentId, const unsigned char* pData, const DWORD cbData);
    HRESULT RemoveContent(CONTENT_ID contentId);
    HRESULT RemoveAllContent();
    VOID OnApplicationEnter();
    VOID OnApplicationExit();
    CContent* GetContent(CONTENT_ID contentId);
    
    LPCWSTR GetGlanceText() { return GetBody(); }
    size_t GetGlanceTextLength() { return wcslen(GetBody()); }
    
private:
    CONTENTMAP m_ContentMap;
};


class CNodeNotification : public CNodeBase
{
public:
    CNodeNotification(const GUID& guidApplicationId, unsigned long ulNotificationId, FILETIME ftExpirationTime)
    {
        m_nodeType = NodeTypeNotification;
        m_guidApplicationId = guidApplicationId;
        m_ulNotificationId = ulNotificationId;
        m_ftExpirationTime = ftExpirationTime;
        m_bViewInitialized = FALSE;
    }

    virtual ~CNodeNotification()
    {}

    unsigned long m_ulNotificationId;
    CFileTime m_ftExpirationTime;
    
    // fake content view for notification
    HRESULT InitializeView(HDC hdc, RECT& rect);
    CContentView m_view;
    CScfContentElement m_fakeNotificationContent;
    BOOL m_bViewInitialized;
};


typedef vector<CNodeApplication*> NODEAPPLICATIONVECTOR;
typedef vector<CNodeNotification*> NODENOTIFICATIONVECTOR;

const size_t INVALID_APPLICATION_NODE_INDEX = (size_t)-1;

